package cn.gotom.pinggu.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;

import cn.gotom.core.web.Constants;
import cn.gotom.core.web.action.MenuInf;
import cn.gotom.core.web.action.SupportAction;
import cn.gotom.pinggu.pojos.Trcc;
import cn.gotom.pinggu.service.DataService;
import cn.gotom.pinggu.service.TrccService;
import cn.gotom.pinggu.vo.Nsrxx;
import cn.gotom.pinggu.vo.Sbsj;
import cn.gotom.pinggu.vo.TrccReport;

import com.google.inject.Inject;

/**
 * 比对报表
 * 
 * @author <a href="mailto:pqixere@qq.com">裴绍国</a>
 * 
 */
public class TrccReportAction extends SupportAction implements MenuInf
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Nsrxx nsrxx;
	private Sbsj sbsj;

	public String list()
	{
		nsrxx = dataService.getNsrxxByNsrdm(trcc.getNsrdm());
		if (nsrxx == null)
		{
			this.setActionmessage("请输入正确的纳税人代码！");
			return Constants.INPUT;
		}
		List<Trcc> trccList = trccService.find(nsrxx.getNsrdm(), trcc.getNd(), trcc.getYf());
		dataList = new ArrayList<TrccReport>();
		for (Trcc t : trccList)
		{
			TrccReport tr = new TrccReport();
			try
			{
				BeanUtils.copyProperties(tr, t);
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}
			Sbsj sbsj = dataService.getSbsjByNsrdm(nsrxx.getNsrdm(), t.getNd(), t.getYf());
			if (sbsj != null)
			{
				tr.setYnse(sbsj.getYnse());
				tr.setRks(sbsj.getRks());
				tr.setRkrq(sbsj.getRkrq());
				tr.setSbsj(sbsj.getSbsj());
			}
			dataList.add(tr);
		}
		return Constants.SUCCESS;
	}

	public String input()
	{
		trcc = new Trcc();
		trcc.setNd(new Date().getYear() + 1900);
		trcc.setYf(new Date().getMonth() + 1);
		return Constants.INPUT;
	}

	protected final Logger log = Logger.getLogger(getClass());

	@Inject
	private TrccService trccService;

	@Inject
	private DataService dataService;

	private Trcc trcc;

	private List<TrccReport> dataList;

	@Override
	public String getName()
	{
		return "数据比对";
	}

	@Override
	public String getGroupName()
	{
		return "数据分析";
	}

	@Override
	public int getMenuSort()
	{
		return 300;
	}

	public Nsrxx getNsrxx()
	{
		return nsrxx;
	}

	public void setNsrxx(Nsrxx nsrxx)
	{
		this.nsrxx = nsrxx;
	}

	public Sbsj getSbsj()
	{
		return sbsj;
	}

	public void setSbsj(Sbsj sbsj)
	{
		this.sbsj = sbsj;
	}

	public Trcc getTrcc()
	{
		return trcc;
	}

	public void setTrcc(Trcc trcc)
	{
		this.trcc = trcc;
	}

	public List<TrccReport> getDataList()
	{
		return dataList;
	}

	public void setDataList(List<TrccReport> dataList)
	{
		this.dataList = dataList;
	}

}
